function log(msg) {
    $('#log').append('<div></div>').append(document.createTextNode(msg));
}

// Callback function used to process the returning message
function transferSuccess(message) {		
	$('#log').append('<div></div>').append(document.createTextNode(
		'Received:: ' + message
	) );
}

// Callback function used to process an error message
function transferFailed(message) {		
	$('#log').append('<div></div>').append(document.createTextNode(
		'Error received:: ' + message
	) );
}

// Creates the TransferRequest "object"
function createTransferRequest(senderName, senderAccountNumber, recipientName, recipientAccountNumber, amount, currency){
	    
    var transferMessage = { 
   		'senderName' : senderName,
   		'senderAccountNumber': senderAccountNumber,
   		'recipientName': recipientName,
   		'recipientAccountNumber': recipientAccountNumber,
   		'amount': amount,
   		'currency': currency,
   	};
   
   	return transferMessage;
}

// Starts the transfer process, invoked right after the connection has been established with the Xmpp server
function startTransfer ( ) {
	var senderName = $("#sname").get(0).value;
	var senderAccount = $("#saccount").get(0).value;
	var recipientName = $("#rname").get(0).value;
	var recipientAccount = $("#raccount").get(0).value;
	var amount = $("#amount").get(0).value;
	var currency = $("#currency").get(0).value;
	 
    var transferRequest	 = createTransferRequest( senderName, senderAccount, recipientName, recipientAccount, amount, currency );
	
	postRequest( "../json/BrillienDispatcherServlet",  "startTransaction", [transferRequest], transferSuccess, transferFailed );
}
